package com.ly.dingtalk.service.file;

import java.io.File;
import java.io.IOException;
import java.util.List;
import java.util.Map;

import com.aliyun.dingtalkstorage_1_0.models.AddFolderRequest;
import com.aliyun.dingtalkstorage_1_0.models.AddFolderResponse;
import com.aliyun.dingtalkstorage_1_0.models.AddSpaceRequest;
import com.aliyun.dingtalkstorage_1_0.models.AddSpaceResponse;
import com.aliyun.dingtalkstorage_1_0.models.CopyDentriesResponse;
import com.aliyun.dingtalkstorage_1_0.models.CopyDentryResponse;
import com.aliyun.dingtalkstorage_1_0.models.DeleteDentriesResponse;
import com.aliyun.dingtalkstorage_1_0.models.DeleteDentryResponse;
import com.aliyun.dingtalkstorage_1_0.models.GetCurrentAppResponse;
import com.aliyun.dingtalkstorage_1_0.models.GetDentryOpenInfoRequest;
import com.aliyun.dingtalkstorage_1_0.models.GetDentryOpenInfoResponse;
import com.aliyun.dingtalkstorage_1_0.models.GetDentryRequest;
import com.aliyun.dingtalkstorage_1_0.models.GetDentryResponse;
import com.aliyun.dingtalkstorage_1_0.models.GetDentryThumbnailsResponse;
import com.aliyun.dingtalkstorage_1_0.models.GetOrgResponse;
import com.aliyun.dingtalkstorage_1_0.models.GetSpaceResponse;
import com.aliyun.dingtalkstorage_1_0.models.ListAllDentriesRequest;
import com.aliyun.dingtalkstorage_1_0.models.ListAllDentriesResponse;
import com.aliyun.dingtalkstorage_1_0.models.ListDentriesRequest;
import com.aliyun.dingtalkstorage_1_0.models.ListDentriesResponse;
import com.aliyun.dingtalkstorage_1_0.models.ListDentryVersionsResponse;
import com.aliyun.dingtalkstorage_1_0.models.MoveDentriesResponse;
import com.aliyun.dingtalkstorage_1_0.models.MoveDentryResponse;
import com.aliyun.dingtalkstorage_1_0.models.RenameDentryResponse;
import com.aliyun.dingtalkstorage_1_0.models.RevertDentryVersionResponse;
import com.aliyun.dingtalkstorage_2_0.models.CommitFileRequest;
import com.aliyun.dingtalkstorage_2_0.models.CommitFileResponse;
import com.aliyun.dingtalkstorage_2_0.models.GetFileUploadInfoRequest;
import com.aliyun.dingtalkstorage_2_0.models.GetFileUploadInfoResponse;
import com.aliyun.dingtalkstorage_2_0.models.SearchDentriesRequest;
import com.aliyun.dingtalkstorage_2_0.models.SearchDentriesResponse;
import com.dingtalk.api.response.OapiMediaUploadResponse;
import com.ly.dingtalk.pojo.file.MediaRequest;

import lombok.NonNull;

/**
 * @author wangzhen 2023/3/15
 */
public interface IDingMediaHandler {

    /**
     * https://open.dingtalk.com/document/orgapp/procedure-for-using-media-files
     * @Description: 上传媒体文件,可以再钉钉的 工作通知 中使用, 官方的案例中就是这样使用的
     * @param mediaRequest
     * @date 2023-12-29 09:39:41
     */
    OapiMediaUploadResponse upload(@NonNull MediaRequest mediaRequest) throws IOException;
    
    /**
     * https://open.dingtalk.com/document/orgapp/obtain-enterprise-storage-related-information
     * 
     * 可以直接在企业管理后台查询存储信息
     * https://oa.dingtalk.com/dingtalk-enterprise-storage.htm#/storage
     * @Description: TODO
     */
    GetOrgResponse storageInfoByunionId(@NonNull String unionId, String corpId);
    
    /**
     * https://open.dingtalk.com/document/orgapp/obtains-the-information-about-the-current-application
     * @Description: 获取当前应用的存储信息
     */
    GetCurrentAppResponse currentAppsStorageInfoByunionId(@NonNull String unionId);
    
    /**
     * https://open.dingtalk.com/document/orgapp/add-space
     * @Description: 添加空间
     * @date 2023-12-28 02:45:38
     */
    AddSpaceResponse addSpaceWithOptions(AddSpaceRequest req);
    
    /**
     * https://open.dingtalk.com/document/orgapp/get-space-information
     * @Description: 获取空间信息
     */
    GetSpaceResponse getSpaceInfoById(@NonNull String spaceId, @NonNull String unionId);
    
    /**
     * https://open.dingtalk.com/document/orgapp/add-folder
     * @Description: 在空间中添加文件夹
     * @date 2023-12-28 03:00:15
     */
    AddFolderResponse addfolders(@NonNull String spaceId, @NonNull String unionId,String parentId, AddFolderRequest req);
    
    /**
     * https://open.dingtalk.com/document/orgapp/copy-an-object
     * @Description: 复制文件或者文件夹
     * @param fromSpaceId 原始文件所在空间id
     * @param fromDentryId 原始文件/文件夹 id
     * @param toSpaceId 目标空间id
     * @param toDentryId 目标文件夹id
     * @param unionId 操作人id
     * @param conflictStrategy 文件和文件夹的名称冲突策略
     *      - AUTO_RENAME：自动重命名，默认值
     *      - OVERWRITE：覆盖
     *      - RETURN_DENTRY_IF_EXISTS：返回已存在文件
     *      - RETURN_ERROR_IF_EXISTS：文件已存在时报错
     */
    CopyDentryResponse copyDentryWithOptions(@NonNull String fromSpaceId,@NonNull String fromDentryId,@NonNull String toSpaceId, @NonNull String toDentryId, @NonNull String unionId,String conflictStrategy);
    
    /**
     * https://open.dingtalk.com/document/orgapp/copy-an-object
     * @Description: 复制文件或者文件夹
     * @param fromSpaceId 原始文件所在空间id
     * @param fromDentries 原始文件/文件夹 id的集合
     * @param toSpaceId 目标空间id
     * @param toDentryId 目标文件夹id
     * @param unionId 操作人id
     * @param conflictStrategy 文件和文件夹的名称冲突策略
     *      - AUTO_RENAME：自动重命名，默认值
     *      - OVERWRITE：覆盖
     *      - RETURN_DENTRY_IF_EXISTS：返回已存在文件
     *      - RETURN_ERROR_IF_EXISTS：文件已存在时报错
     */
    CopyDentriesResponse copyDentriesWithOptions(@NonNull String fromSpaceId,List<String> fromDentries,@NonNull String toSpaceId, @NonNull String toDentryId, @NonNull String unionId,String conflictStrategy);
    
    /**
     * https://open.dingtalk.com/document/orgapp/move-a-file-or-folder
     * @Description: 移动文件或者文件夹
     * @param fromSpaceId 原始文件所在空间id
     * @param fromDentryId 原始文件/文件夹 id
     * @param toSpaceId 目标空间id
     * @param toDentryId 目标文件夹id
     * @param unionId 操作人id
     * @param conflictStrategy 文件和文件夹的名称冲突策略
     *      - AUTO_RENAME：自动重命名，默认值
     *      - OVERWRITE：覆盖
     *      - RETURN_DENTRY_IF_EXISTS：返回已存在文件
     *      - RETURN_ERROR_IF_EXISTS：文件已存在时报错
     */
    MoveDentryResponse moveDentryWithOptions(@NonNull String fromSpaceId,@NonNull String fromDentryId,@NonNull String toSpaceId, @NonNull String toDentryId, @NonNull String unionId,String conflictStrategy);
    
    /**
     * https://open.dingtalk.com/document/orgapp/copy-an-object
     * @Description: 批量移动文件或者文件夹
     * @param fromSpaceId 原始文件所在空间id
     * @param fromDentries 原始文件/文件夹 id的集合
     * @param toSpaceId 目标空间id
     * @param toDentryId 目标文件夹id
     * @param unionId 操作人id
     * @param conflictStrategy 文件和文件夹的名称冲突策略
     *      - AUTO_RENAME：自动重命名，默认值
     *      - OVERWRITE：覆盖
     *      - RETURN_DENTRY_IF_EXISTS：返回已存在文件
     *      - RETURN_ERROR_IF_EXISTS：文件已存在时报错
     */
    MoveDentriesResponse moveDentriesWithOptions(@NonNull String fromSpaceId,List<String> fromDentries,@NonNull String toSpaceId, @NonNull String toDentryId, @NonNull String unionId,String conflictStrategy);
    
    /**
     * https://open.dingtalk.com/document/orgapp/rename-a-file-or-folder
     * @Description: 重命名文件或文件夹
     * @param unionId 操作人id
     * @param newName 文件或文件夹的新名称
     * @param spaceId 空间id
     * @param dentryId 文件或文件夹Id
     * @date 2023-12-28 04:35:39
     */
    RenameDentryResponse renameDentryWithOptions(@NonNull String unionId,@NonNull String newName,@NonNull String spaceId,@NonNull String dentryId);
    
    /**
     * https://open.dingtalk.com/document/orgapp/delete-a-file-or-folder
     * @Description: 删除文件/文件夹
     * @param unionId 操作人id
     * @param toRecycleBin 删除后,是否备份到回收站, true: 是
     * @param spaceId 空间Id
     * @param dentryId 需要被删除的文件或文件夹Id。
     * @date 2023-12-28 04:40:58
     */
    DeleteDentryResponse deleteDentryWithOptions(@NonNull String unionId, Boolean toRecycleBin,@NonNull String spaceId,@NonNull String dentryId);
    
    /**
     * https://open.dingtalk.com/document/orgapp/delete-a-file-or-folder
     * @Description: 批量删除文件/文件夹
     * @param unionId 操作人id
     * @param toRecycleBin 删除后,是否备份到回收站, true: 是
     * @param spaceId 空间Id
     * @param dentryId 需要被删除的文件或文件夹Id。
     * @date 2023-12-28 04:40:58
     */
    DeleteDentriesResponse deleteDentriesWithOptions(@NonNull String unionId, Boolean toRecycleBin,@NonNull String spaceId, List<String> dentriesId);
    
    /**
     * https://open.dingtalk.com/document/orgapp/obtains-a-list-of-file-versions
     * @Description: 如果文件名策略使用的是OVERWRITE，当出现上传同名文件时，该文件会产生历史版本
     * @param spaceId 空间id
     * @param dentryId 文件/文件夹id
     * @param unionId 操作人id
     * @param maxResults 每页代销
     * @param nextToken 分页游标
     * @date 2023-12-28 08:42:08
     */
    ListDentryVersionsResponse listDentryVersionsWithOptions(@NonNull String spaceId,@NonNull String dentryId,@NonNull String unionId,Integer maxResults, String nextToken);
    
    /**
     * https://open.dingtalk.com/document/orgapp/restore-previous-versions-of-files
     * @Description: 例如，有一个文件名为测试文件.txt，目前最新版本为5。调用本接口可以把该文件恢复为第3版本。接口调用成功后，测试文件.txt的最新版本为6，文件内容与第3版本一致。
     * @param spaceId
     * @param dentryId
     * @param unionId
     * @param version
     * @date 2023-12-28 08:47:11
     */
    RevertDentryVersionResponse revertDentryVersionWithOptions(@NonNull String spaceId,@NonNull String dentryId,@NonNull String unionId,@NonNull String version);
    
    /**
     * https://open.dingtalk.com/document/orgapp/obtain-the-file-list-storage
     * @Description: 本接口没有递归功能，只能获取当前父目录下的文件或者文件夹。
     * @param req
     * @date 2023-12-28 08:51:06
     */
    ListDentriesResponse listDentriesWithOptions(@NonNull String spaceId, ListDentriesRequest req);
    
    /**
     * https://open.dingtalk.com/document/orgapp/get-a-list-of-all-files-or-folders-under-a
     * @Description: 调用本接口，平铺归获取指定空间内的所有文件或者文件夹列表。
     * @param spaceId
     * @param req
     * @date 2023-12-28 08:54:25
     */
    ListAllDentriesResponse listAllDentriesWithOptions(@NonNull String spaceId, ListAllDentriesRequest req);
    
    /**
     * https://open.dingtalk.com/document/orgapp/obtains-the-object-preview-or-editing-information
     * @Description: 调用本接口，获取文件预览或编辑的链接。
     * @param spaceId
     * @param dentryId
     * @param req
     * @date 2023-12-28 08:58:57
     */
    GetDentryOpenInfoResponse getDentryOpenInfoWithOptions(@NonNull String spaceId,@NonNull String dentryId,GetDentryOpenInfoRequest req);
    
    /**
     * https://open.dingtalk.com/document/orgapp/get-file-thumbnails-in-bulk
     * @Description: 批量获取文件缩略图
     * @param spaceId
     * @param dentriesId
     * @param unionId
     * @date 2023-12-28 09:02:48
     */
    GetDentryThumbnailsResponse getDentryThumbnailsWithOptions(@NonNull String spaceId,List<String> dentriesId,@NonNull String unionId);
    
    /**
     * https://open.dingtalk.com/document/orgapp/search-for-files
     * @Description: 搜索文件
     * @param req
     * @date 2023-12-28 10:32:14
     */
    SearchDentriesResponse searchDentriesWithOptions(SearchDentriesRequest req);
    /**
     * 
     * https://open.dingtalk.com/document/orgapp/obtain-file-upload-informations
     * @Description: 获取文件上传信息
     * @param dentryId
     * @param req
     * @date 2023-12-28 10:17:01
     */
    GetFileUploadInfoResponse getFileUploadInfoWithOptions(@NonNull String parentDentryUuid, GetFileUploadInfoRequest req);
    
    /**
     * 普通的附件上传
     * @MethodName: uploadFile
     * @Description: TODO
     * @author wangzhen
     * @return Boolean
     * @date 2023-12-28 10:46:17
     */
    public Boolean uploadFile(File file,Map<String, String> headers ,String resourceUrl);
    
    /**
     * https://open.dingtalk.com/document/orgapp/submittal-file
     * @Description: 提交文件
     * @param parentDentryUuid
     * @param req
     * @date 2023-12-28 10:59:26
     */
    CommitFileResponse commitFileWithOptions(@NonNull String parentDentryUuid,CommitFileRequest req);
    
    /**
     * https://open.dingtalk.com/document/orgapp/obtain-file-or-folder-information
     * @Description: 获取文件或文件夹信息
     * @param spaceId
     * @param dentryId
     * @param req
     * @date 2023-12-29 09:22:39
     */
    GetDentryResponse getDentryWithOptions(@NonNull String spaceId,@NonNull String dentryId, GetDentryRequest req);
}
